<template>
  <div>
    {{msg}}
    <p>
      <span>{{times+"秒之后，自动跳转到首页..."}}</span>
    </p>
    <img src="" alt="">
    <img src="blob:http://localhost:8088/e540c46a-be49-456d-bd7d-e289c84bcfdd" alt="">
  </div>
</template>

<script>
  export default {
    data() {
      return {
        name: "ZhiFuBao",
        msg: "支付成功！",
        times: 5,
      }
    },
    mounted() {
      this.showTime();
      this.updateState();
    },
    methods: {
      updateState() {
        this.$http.post('http://localhost:8888/order/query', {emulateJSON: true})
          .then(res => {
            let orders = res.data.data;
            orders.forEach((item, index, list) => {
              if (item.orderId === location.hash.match(/out_trade_no=(\S*)&method/)[1]) {
                item.state = "待发货";
                this.$http.post('http://localhost:8888/order/update', item, {emulateJSON: true}).then(res => {
                });
              }

            })
          })
      },
      showTime() {
        console.log(123456789);
        this.updateState();
        this.timer = setInterval(()=>{
          this.times--;
          if(this.times===0){
            clearInterval(this.timer);
            this.$router.push({path:"/IndexLayout"});
          }
        },1000)
      }
    },
  }
</script>

<style scoped>

</style>
